<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>会议统计</span>
            </div>
          </template>
          <div class="stat-content">
            <div class="stat-item">
              <div class="stat-title">本月会议总数</div>
              <div class="stat-number">{{ totalMeetings }}</div>
            </div>
            <div class="stat-item">
              <div class="stat-title">已完成会议</div>
              <div class="stat-number">{{ completedMeetings }}</div>
            </div>
            <div class="stat-item">
              <div class="stat-title">平均时长</div>
              <div class="stat-number">{{ averageDuration }}分钟</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>会议趋势</span>
              <el-radio-group v-model="timeRange" size="small">
                <el-radio-button label="week">本周</el-radio-button>
                <el-radio-button label="month">本月</el-radio-button>
                <el-radio-button label="year">本年</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-container">
            <!-- TODO: 集成图表组件 -->
            <div class="empty-chart">图表区域</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>会议类型分布</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- TODO: 集成饼图组件 -->
            <div class="empty-chart">饼图区域</div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>部门会议统计</span>
            </div>
          </template>
          <div class="chart-container">
            <!-- TODO: 集成柱状图组件 -->
            <div class="empty-chart">柱状图区域</div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-card style="margin-top: 20px">
      <template #header>
        <div class="card-header">
          <span>会议记录</span>
          <div class="filter-container">
            <el-date-picker
              v-model="listQuery.dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              class="filter-item"
              style="width: 300px"
            />
            <el-select
              v-model="listQuery.type"
              placeholder="会议类型"
              clearable
              class="filter-item"
              style="width: 130px"
            >
              <el-option label="部门会议" value="department" />
              <el-option label="项目会议" value="project" />
              <el-option label="培训会议" value="training" />
              <el-option label="其他会议" value="other" />
            </el-select>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="handleFilter"
            >
              搜索
            </el-button>
          </div>
        </div>
      </template>

      <el-table
        v-loading="listLoading"
        :data="list"
        border
        fit
        highlight-current-row
      >
        <el-table-column label="会议主题" prop="title" align="left" min-width="200" />
        <el-table-column label="会议类型" prop="type" align="center" width="100">
          <template #default="{row}">
            <el-tag :type="row.type === 'department' ? 'primary' : row.type === 'project' ? 'success' : 'info'">
              {{ row.type === 'department' ? '部门会议' : row.type === 'project' ? '项目会议' : row.type === 'training' ? '培训会议' : '其他会议' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="主持人" prop="host" align="center" width="120" />
        <el-table-column label="开始时间" prop="startTime" align="center" width="180" />
        <el-table-column label="时长" prop="duration" align="center" width="100">
          <template #default="{row}">
            {{ row.duration }}分钟
          </template>
        </el-table-column>
        <el-table-column label="参会人数" prop="attendees" align="center" width="100" />
        <el-table-column label="操作" align="center" width="150">
          <template #default="{row}">
            <el-button
              size="small"
              type="primary"
              @click="handleViewDetail(row)"
            >
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="listQuery.page"
        v-model:limit="listQuery.limit"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const timeRange = ref('month')
const listLoading = ref(false)
const list = ref([])
const total = ref(0)

// 统计数据
const totalMeetings = ref(0)
const completedMeetings = ref(0)
const averageDuration = ref(0)

const listQuery = ref({
  page: 1,
  limit: 20,
  dateRange: [],
  type: ''
})

const getList = async () => {
  listLoading.value = true
  try {
    // TODO: 调用API获取会议列表
    listLoading.value = false
  } catch (error) {
    console.error('获取会议列表失败:', error)
    listLoading.value = false
  }
}

const handleFilter = () => {
  listQuery.value.page = 1
  getList()
}

const handleViewDetail = (row) => {
  router.push(`/meeting/detail/${row.id}`)
}

// 初始化加载数据
getList()
</script>

<style lang="scss" scoped>
.stat-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stat-item {
  text-align: center;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 4px;

  .stat-title {
    color: #606266;
    font-size: 14px;
    margin-bottom: 10px;
  }

  .stat-number {
    color: #303133;
    font-size: 24px;
    font-weight: bold;
  }
}

.chart-container {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-chart {
  color: #909399;
  font-size: 14px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-container {
  display: flex;
  gap: 10px;
  align-items: center;
}
</style>